package com.fire.market.controller;

import com.fire.component.dto.Response;
import com.fire.component.dto.SingleResponse;
import com.fire.component.extension.Assert;

import com.fire.market.gateway.api.dto.UserInfo;
import com.fire.market.service.impl.UserQueryCoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
@Slf4j
@RestController
@RequestMapping("/user/query")
@Api(tags = "用户query操作")
public class UserQueryController extends BaseController{
    @Resource
    private UserQueryCoreService userQueryCoreService;

    //获取用户详情
    @GetMapping("getInfo/{userId}")
    @ApiOperation(value = "用户详细信息", notes = "获取用户的详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "userId", value = "用户ID", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "header",name = "userToken", value = "用户Token", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "path",name = "userId", value = "用户ID", required = true, dataType = "Integer")
    })
    public SingleResponse<UserInfo> queryUserInfo(@PathVariable("userId") Integer userId){
        Assert.notNull(userId, "userId is null");
        UserInfo userInfo = userQueryCoreService.queryUserInfo(userId);
        return SingleResponse.of(userInfo);
    }

    //获取用户opt
    @PostMapping(value = "getOtp/{telephone}")
    @ApiOperation(value = "获取用户的手机验证码", notes = "获取optCode")
    @ApiImplicitParam(name = "telephone", value = "用户手机", required = true, dataType = "String")
    public Response getUserOpt(@PathVariable("telephone") String telephone){
        Assert.notNull(telephone, "telephone is null");
        userQueryCoreService.queryOpt(telephone);
        return Response.buildSuccess();
    }
}
